---
name: Using Subscriptions
---

# Using Subscriptions

Genql has a built in subscription client that returns an observable

Additional options are passed down to `subscriptions-transport-ws`

```js
import { createClient, everything } from './generated'

const client = createClient({
    url: 'ws://my-url',
    headers: {
        Authorization: 'Bearer ...',
    },
})

const { unsubscribe } = await client
    .subscription({
        user: {
            ...everything,
        },
    })
    .subscribe({
        next: (x) => console.log('next', x),
        error: console.error,
    })

// using chain syntax
const { unsubscribe } = await client.chain.subscription
    .user({ where: { name: { _eq: 'John' } } })
    .get({ ...everything })
    .subscribe({
        next: (x) => console.log('next', x),
        error: console.error,
    })

unsubscribe()
```
